package com.chucang.shucang.bac.controller;

import com.chucang.shucang.bac.entity.ServiceChargeEntity;
import com.chucang.shucang.bac.service.ServiceChargeService;
import com.chucang.shucang.bac.vo.ConsignChargeVO;
import com.chucang.shucang.bac.vo.WithdrawChargeVO;
import com.chucang.shucang.common.base.utils.R;
import com.chucang.shucang.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务费条目
 *
 * @author flitsneak flitsneak@gmail.com
 * @since 1.0.0 2022-10-22
 */
@RestController
@RequestMapping("/servicecharge")
@RequiredArgsConstructor
@Api(tags = "服务费")
public class ServiceChargeController {

    private final ServiceChargeService serviceChargeService;

    /**
     * 获取寄售服务费率
     *
     * @return r
     */
    @Inner(value = false)
    @Cacheable(value = "consignCharge")
    @GetMapping("/getConsignCharge")
    public R<ConsignChargeVO> getConsignCharge() {
        ServiceChargeEntity byId = serviceChargeService.getById(1);
        ConsignChargeVO consignChargeVO = new ConsignChargeVO();
        consignChargeVO.setChargeTitle(byId.getChargeTitle());
        consignChargeVO.setChargeRate(byId.getChargeRate());
        return R.ok(consignChargeVO);
    }

    /**
     * 提现服务费率
     *
     * @return r
     */
    @Inner(value = false)
    @Cacheable(value = "withdrawBalanceCharge")
    @GetMapping("/getWithdrawBalanceCharge")
    public R<WithdrawChargeVO> getWithdrawBalanceCharge() {
        ServiceChargeEntity byId = serviceChargeService.getById(2);
        WithdrawChargeVO withdrawChargeVO = new WithdrawChargeVO();
        withdrawChargeVO.setChargeTitle(byId.getChargeTitle());
        withdrawChargeVO.setChargeRate(byId.getChargeRate());
        return R.ok(withdrawChargeVO);
    }

}